package com.baor.controller;

import com.baor.domain.AdminVo;
import com.baor.service.AdminService;
import com.baor.utils.AjaxResult;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;
import java.util.Map;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/login")
    public AjaxResult<?> login(@RequestBody AdminVo adminVo){
       return this.adminService.login(adminVo);
    }

    @RequestMapping("/list")
    public AjaxResult<?> list(@RequestBody Map<String,Object> params){
        return this.adminService.list(params);
    }

    @RequestMapping("/insert")
    public AjaxResult<?> insert(@RequestBody  AdminVo adminVo){
        try {
            return this.adminService.insert(adminVo);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }

    @RequestMapping("/delete")
    public AjaxResult<?> delete(int adminId){
        return this.adminService.delete(adminId);
    }

    @RequestMapping("/update")
    public AjaxResult<?> update(@RequestBody AdminVo adminVo) {
        return  this.adminService.update(adminVo);
    }

    @RequestMapping("/shopAdmin")
    public AjaxResult<?> shopAdmin(int adminId){
        return this.adminService.shopAdmin(adminId);
    }
}
